package giaodien;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.PopupMenu;
import java.awt.TextField;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
import javax.swing.Popup;

import controller.MatHangController;
import controller.NhanVienController;
import controller.UserController;
import model.MatHang;
import model.NhaCC;

import java.awt.SystemColor;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Dimension;

import javax.swing.UIManager;

public class TrangChu extends JFrame {

	private JPanel contentPane;
	static String ten;
	static int idnv;
	static TextField textField_7;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TrangChu frame = new TrangChu("");
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TrangChu(final String user) {
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 650, 401);
		contentPane = new JPanel();
		contentPane.setForeground(new Color(72, 61, 139));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		// button lap hoa don
		JButton btnNewButton = new JButton("Hóa đơn xuất");
		btnNewButton.setBackground(UIManager.getColor("CheckBox.background"));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				HoaDonXuat h1 = new HoaDonXuat(user);
				// h1.setSize(750, 500);
				//textField_7.setText("rdgf");
				h1.setVisible(true);
			}
		});
		btnNewButton.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/hoadon.png")));
		btnNewButton.setBounds(35, 101, 165, 53);
		contentPane.add(btnNewButton);

		JButton btnKhchHng = new JButton("Kh\u00E1ch h\u00E0ng");
		btnKhchHng.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				KhachHang k = new KhachHang(user);
//				JFrame f = new JFrame();
//				f.getContentPane().add(k);
//				f.setSize(550, 600);
//				f.setLocation(100, 100);
				// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				k.setVisible(true);
			}
		});
		btnKhchHng.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/khachhang.png")));
		btnKhchHng.setBounds(234, 174, 165, 53);
		contentPane.add(btnKhchHng);

		JButton btniL = new JButton("\u0110\u1EA1i l\u00FD");
		btniL.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				giaodien.NhaCC n = new giaodien.NhaCC(user);
				n.setVisible(true);
			}
		});

		btniL.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/provider.png")));
		btniL.setBounds(433, 174, 165, 53);
		contentPane.add(btniL);

		JButton btnNewButton_1 = new JButton("S\u1EA3n ph\u1EA9m");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SanPham s = new SanPham(user);
				s.setVisible(true);
				
			}
		});
		btnNewButton_1.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/product.png")));
		btnNewButton_1.setBounds(433, 101, 165, 53);
		contentPane.add(btnNewButton_1);

		JButton btnNewButton_2 = new JButton("Quản lý HĐ");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// if (user.equals(user)) {
				KoDuocQLNV k = new KoDuocQLNV();
				JFrame f = new JFrame();
				f.getContentPane().add(k);
				f.setSize(550, 600);
				f.setLocation(100, 100);
				// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				f.setVisible(true);
				// }
			}
		});
		btnNewButton_2.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/hoadon1.png")));
		btnNewButton_2.setBounds(35, 174, 165, 53);
		contentPane.add(btnNewButton_2);

		JButton btnNewButton_3 = new JButton("Nh\u00E2n vi\u00EAn");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				NhanVien n = new NhanVien(user);
				n.setVisible(true);
			}
		});
		btnNewButton_3.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/nhanvien.png")));
		btnNewButton_3.setBounds(35, 251, 165, 54);
		contentPane.add(btnNewButton_3);

		JLabel lblPhnMmQun = new JLabel(
				"PH\u1EA6N M\u1EC0M QU\u1EA2N L\u00DD C\u1EECA H\u00C0NG \u0110I\u1EC6N M\u00C1Y");
		lblPhnMmQun.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblPhnMmQun.setForeground(new Color(0, 0, 139));
		lblPhnMmQun.setBounds(35, 24, 388, 30);
		contentPane.add(lblPhnMmQun);
		// tên nhân viên đang làm việc
		JLabel lblMNhnVin = new JLabel("Xin chào ");
		lblMNhnVin.setBounds(435, 28, 74, 16);
		contentPane.add(lblMNhnVin);
		// /////////////////////
		UserController u = new UserController();
		NhanVienController c = new NhanVienController();
		int id = u.getUser(user).getIdnv();
		ten = c.getNhanVien(id).getTenNV();
		JLabel label = new JLabel("");
		label.setBounds(497, 28, 125, 16);
		contentPane.add(label);
		label.setText(ten);

		JButton btnNewButton_4 = new JButton("Đăng xuất");
		btnNewButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DangNhap d = new DangNhap();
				d.setVisible(true);
				dispose();
			}
		});
		btnNewButton_4.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/logout.png")));
		btnNewButton_4.setBounds(433, 53, 128, 26);
		contentPane.add(btnNewButton_4);
		
		JButton btnNewButton_5 = new JButton("Hóa đơn nhập");
		btnNewButton_5.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/Package-Add-icon.png")));
		btnNewButton_5.setBounds(234, 101, 165, 53);
		contentPane.add(btnNewButton_5);
		
		JButton btnNewButton_6 = new JButton("Báo cáo");
		btnNewButton_6.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/report.png")));
		btnNewButton_6.setBounds(234, 251, 165, 53);
		contentPane.add(btnNewButton_6);
		
		JButton btnNewButton_7 = new JButton("Hướng dẫn");
		btnNewButton_7.setIcon(new ImageIcon(TrangChu.class.getResource("/icon/stock_task_assigned_to.png")));
		btnNewButton_7.setBounds(433, 251, 165, 53);
		contentPane.add(btnNewButton_7);
	}

	private static void addPopup(Component component, final JPopupMenu popup) {
		component.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}

			public void mouseReleased(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}

			private void showMenu(MouseEvent e) {
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		});
	}
}
